package com.jweb.framework.core.config;

import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;

import com.jweb.framework.core.impl.SimpleProcessExecutor;

/** 
 * @author Thomas: 
 * 类说明 :对简单流程模板解析
 */
public class TopSimpleExecutorParser extends AbstractSingleBeanDefinitionParser {
	
	protected String getBeanClassName(Element ele) {
		String className = ele.getAttribute("class");
		if(StringUtils.hasText(className)){
			return className ;
		}
		
		return SimpleProcessExecutor.class.getName() ;
	}
	
	/**
	 * 对自定义simple-template解析，并加载入Spring IOC容器
	 */
	protected void doParse(Element ele , ParserContext parserContext , BeanDefinitionBuilder beanDefinitionBuilder) {
		
		beanDefinitionBuilder.addPropertyValue("jservices", ActionParser.createActions(ele , parserContext));
		String transactional = ele.getAttribute("transactional");
		if(StringUtils.hasText(transactional)){
			beanDefinitionBuilder.addPropertyReference("transactional", transactional);
		}
		beanDefinitionBuilder.addPropertyValue("name", ele.getAttribute("id"));
	}
}
